package core;

import constant.Constant;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MyFrame extends JPanel implements KeyListener {

    private static final long serialVersionUID = -3149926831770554380L;

    JFrame jFrame = new JFrame();

    public MyFrame() {}

    public void loadFrame(){
        this.setDoubleBuffered(true);
        jFrame.add(this);
        jFrame.addKeyListener(this);
        jFrame.setTitle("snake");
        jFrame.setSize(Constant.GAME_WIDTH,Constant.GAME_HEIGHT);
        jFrame.setLocationRelativeTo(null);
        jFrame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                super.windowClosing(e);
                System.exit(0);
            }
        });
        jFrame.setVisible(true);
        new MyThread().start();
    }

    class MyThread extends Thread{
        @Override
        public void run() {
            super.run();
            while (true){
                repaint();
                try {
                    sleep(30);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }



    @Override
    public void keyTyped(KeyEvent e) {

    }

    @Override
    public void keyPressed(KeyEvent e) {

    }

    @Override
    public void keyReleased(KeyEvent e) {

    }
}
